import { Inject, Controller, Post, Body } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { UserService } from '../service/user.service';

@Controller('/user')
export class UserController {
  @Inject()
  ctx: Context;

  @Inject()
  userService: UserService;

  @Post('/save')
  async save(@Body() userParams) {
    console.log(userParams);
    const user = await this.userService.saveUser({ ...userParams });

    return {
      success: true,
      message: 'OK',
      data: {
        ...user,
      },
    };
  }

  @Post('/list')
  async list() {
    const list = await this.userService.listUser();
    return {
      success: true,
      message: 'OK',
      data: {
        list,
      },
    };
  }
}
